<template>
	<view class="home">
		<view class="" style="display: flex;align-items: center;justify-content: space-around;padding: 0 20rpx;"
			v-show="devName == '创建'">
			<view class="" style="width: 100%;display: flex;justify-content: space-between;align-items: center;">
				<u-button @click="createRainGauge" class="custom-style" type="primary" text="创建雨量站分组"></u-button>
				<u-button @click="createRainyulz" class="custom-style" type="success" text="创建人工雨量站"></u-button>
			</view>
			<!-- 雨量站 -->
			<u-modal :show="showGauge" title="创建雨量站分组" @confirm='confirm' @cancel="cancel" :showCancelButton="true">
				<view class="slot-content">
					<u--input placeholder="请输入内容" border="surround" v-model="value"></u--input>
				</view>
			</u-modal>
			<!-- 人工 -->
			<u-modal :show="showGauyulz" title="选择雨量站分组" @confirm='confyulz' @cancel="cancyulz"
				:showCancelButton="true">
				<view class="checkbox-content">
					<view class="box">
						<uni-data-checkbox width="700rpx" v-model="radio1" :localdata="vlikbox"
							mode="tag"></uni-data-checkbox>
					</view>
					<view class="">
						<u--input placeholder="请输入雨量站名称" border="surround" v-model="valuyulz"></u--input>
					</view>

				</view>
			</u-modal>
		</view>
		<view class="devitem">
			<view class="devitem_flx" v-for="(i,index) in dataList" :key="index" @click="devitFn(i)">
				<image class="imgim" src="/static/xcel.png" mode=""></image>
				<view class="yuan">
					{{i.groupName}}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				devName: '',
				showGauge: false,
				value: '',
				showGauyulz: false,
				valuyulz: '',
				radio1: null,
				vlikbox: []
			}
		},
		onLoad(option) {
			this.devName = option.name
			console.log(option.name);
		},
		onShow() {
			this.upCallback()
		},
		methods: {
			// 创建人工雨量站分组
			createRainGauge() {
				this.showGauge = true
			},
			confirm() {
				if (this.value == '') {
					uni.showToast({
						title: '未填写信息',
						duration: 1000
					});
					return
				}
				uni.$u.http.post('/api/device/device/addRainFallStationGroup', {
					"groupName": this.value
				}).then(res => {
					console.log(res);
					if (res.code == 200) {
						uni.showToast({
							title: '上传成功',
							duration: 1000
						});
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 1200)
					}
				}).catch(err => {
					console.log('错误', err);
				})
				this.showGauge = false
			},
			cancel() {
				this.showGauge = false
			},
			// 创建人工雨量站
			createRainyulz() {
				this.radio1 = ''
				this.showGauyulz = true
			},
			confyulz() {
				if (this.valuyulz == '' || this.radio1 == '') {
					uni.showToast({
						title: '未填写信息',
						duration: 1000
					});
					return
				}
				uni.$u.http.post('/api/device/device/addRenGongRainFallStation', {
					"name": this.valuyulz,
					"rfsgId": this.radio1
				}).then(res => {
					console.log(res);
					if (res.code == 200) {
						uni.showToast({
							title: '上传成功',
							duration: 1000
						});
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							});
						}, 1200)
					}
				}).catch(err => {
					console.log('错误', err);
				})
				this.showGauyulz = false
			},
			cancyulz() {
				this.showGauyulz = false
			},
			// 人工测报
			devitFn(i) {
				console.log('i', i);
				if (this.devName == '自计') {
					uni.redirectTo({
						url: '/pages/index/rainfallStation?id=' + i.id + '&name=' + i.groupName
						// url: '/pages/index/setUp'
					});
				}
				if (this.devName == '人工') {
					uni.redirectTo({
						url: '/pages/index/manualForecasting?id=' + i.id + '&name=' + i.groupName
						// url: '/pages/index/setUp'
					});
				}
				// 雨量站列表
				console.log('this.devName', this.devName);
				if (this.devName == '每日降雨量') {
					uni.navigateTo({
						url: '/pages/index/listOfRainMeasuringStations?id=' + i.id + '&name=' + i.groupName
					});
				}
				// 雨量站列表
				if (this.devName == '年度雨量') {
					uni.navigateTo({
						url: '/pages/statistics/yearsAnnualRainfall?id=' + i.id + '&name=' + i.groupName
					});
				}
				// 自计人工对比
				if (this.devName == '统计对比') {
					uni.navigateTo({
						url: '/pages/statistics/statisticalComparison?id=' + i.id + '&name=' + i.groupName
						// url: '/pages/index/setUp'
					});
				}

			},
			upCallback() {
				uni.$u.http.get('/api/device/device/getRainFallStationGroupList').then(res => {
					if (res.code == 200) {
						console.log(res.rows);
						this.dataList = res.rows
						let arr = []
						arr = res.rows.map((i) => {
							return {
								text: i.groupName,
								value: i.id
							}
						})
						this.vlikbox = arr
						console.log('this.vlikbox', this.vlikbox);
					} else {
						uni.showToast({
							title: '暂无数据',
							duration: 1500
						});
					}
				}).catch(err => {
					console.log('err', err);
					//  请求失败,隐藏加载状态
					this.mescroll.endErr()
				})
			},
			// 电量
			electricFn(data) {
				let nub = (data - 8) / (12 - 8) * 100
				return nub.toFixed(0)
			},
		}
	}
</script>
<style scoped lang="scss">
	.checkbox-content {}

	.home {
		.custom-style {
			// background-color: #f2f1f6;
			width: 320rpx;
		}

		.devitem {
			padding: 30rpx;
			border-radius: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			flex-wrap: wrap;

			.devitem_flx {
				width: 300rpx;
				margin: 10rpx 0;
				padding: 20rpx;
				border-radius: 30rpx;
				background-color: rgba(255, 255, 255, 0.9);

				.imgim {
					width: 60rpx;
					height: 60rpx;
					margin-right: 20rpx;
				}

				.yuan {
					color: #000;
					font-size: 45rpx;
				}
			}

		}
	}
</style>
<style>
	@font-face {
		font-family: 'MyFont';
		src: url('@/static/fonts/LED.otf');
	}

	page {
		background-color: #f2f1f6;
	}
</style>